var myiscroll=null;
var gyear="";
$(document).ready(function(){
	leftmenu("#leftmenu","#wrap");
	var hrefYear="";
//	var url = location.href.split('?')[1];
//	if(url!=null){
//		var arr = url.split('&');
//		for(var i = 0 ; i < arr.length;i++){
//			var temp = arr[i];
//			var tempArr = temp.split('=');
//			var key = tempArr[0];
//			if(key == "year"){
//				hrefYear=tempArr[1];
//			}
//		}
//	}
	hrefYear = getQueryParam("year");
	inin();       //初始化操作
	tabChange();  //年份切换方法
	if(hrefYear!=""){
		tabChange1(hrefYear);
	}else{
		querySalary(gyear); //查询出当年的所有薪水方法
	}
	$("#errorBtncancel").on("tap",function(){
		$("#errorMask").hide();
	});
	$("#toMyfund").on("tap",function(){
		gotoLocation("/mobile/myfund/mszq.html","");
	});
});

function inin(){
	var date = new Date();  
	gyear = date.getFullYear(); //得到完整年份
	var lis = $("#J-TabsNav > li");//根据当前年算出最近两年
	$(lis[0]).text(gyear-2+"年");
	$(lis[1]).text(gyear-1+"年");
	$(lis[2]).text(gyear+"年");
}

function querySalary(syear){  
	$("#loadingText").show();
	iscroll();
	$.ajax({
		type : "post", 
		url: mpsurl+"/mobile/salary/getsalaryList.do",
		dataType: "json",
		data : {year:syear},
		success : function(data){
			$("#loadingText").hide();
			if(data.resultCode=="500600"){
				var obj = data.value;
				if(obj[0].year_item=="-1"){
					$("#mysalary").hide();
					$("#norecord").show();
				}else{
					$(".detail-record-list").empty();
					$("#mysalary").show();
					$("#norecord").hide();
				 	for(var i=0; i<obj.length; i++){
					 	//var empl_rcd = obj[i].empl_rcd;      //雇佣记录编号  
					 	var year = obj[i].year;    //年份
					 	var year_item = obj[i].year_item;  
					 	var month = obj[i].month;
					 	if(month<10)
					 		month = month.substr(1,1);
					 	//var month = parseInt(obj[i].month); //月
					 	var paic_gprslt_col153 = obj[i].col153; //净收入
					 	var index = paic_gprslt_col153.indexOf(".");
						var paic_gprslt_col153_intger = paic_gprslt_col153.substring(0, index);  //净收入整数部分
						var paic_gprslt_col153_decimal = paic_gprslt_col153.substring(index); 	//净收入小树部分
					 	var paic_gprslt_col152 = obj[i].col152;  //收入项合计
					 	var paic_gprslt_col13 = obj[i].col13;    //扣项合计
					 	
						var li = $("<li><input type=\"hidden\" value=\"emplid=134&year="+year+"&year_item="+year_item+"&itemLen="+obj.length+"\"/>"+
		                           "<div class=\"detail-record-list-cont\">"+
		                           "<span class=\"css-icon\"></span>"+
		                           "<div class=\"list-cont\">"+
		                           "<div class=\"detail-record-time\">"+
		                           "<p class=\"time-txt\">净收入</p>"+
		                           "<p class=\"time-money\">"+paic_gprslt_col153_intger+"<span>"+paic_gprslt_col153_decimal+"</span></p>"+
		                           "</div>"+
		                           "<div class=\"detail-record-cont\">"+
		                           "<div class=\"record-cont-up\"><span>收入：</span>"+paic_gprslt_col152+"</div>"+
		                           "<div class=\"record-cont-down\"><span>扣减：</span>"+paic_gprslt_col13+"</div>"+
		                           "</div>"+
		                           "</div>"+
		                           "</div>"+
		                           "<figure class=\"css-icon-circle\">"+month+"<span>月</span></figure>"+
		                           "</li>");
		                 li.on("tap",function(){
		                 	var param = $(this).find("input[type=hidden]").val();
		                 	gotoLocation("/mobile/mysalary/xiangqing.html",param);
		                 });
		                 if(i>0 && obj[i].month==obj[i-1].month){
					 		li.find("figure.css-icon-circle").remove();
					 	}
					 	$(".detail-record-list").append(li);
					}
				}
				iscroll();
			}else{
				var tourl = "/mobile/mysalary/gzd-chaxun.html?year="+syear;
            	checkLogin(data.resultCode,tourl,data.resultMessage);
			}
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			$("#loadingText").hide();
			//errorMask("网络异常");
			setPromptForInput("网络异常");
		}
	});
}

function tabChange(){ //设置年份tab栏上的鼠标效果和事件
	var lis = $("#J-TabsNav > li");  //得到所有TAB上的li标签
	for(var i=0; i<lis.length; i++){
		$(lis[i]).click(function(){    //设置鼠标点击的效果
			for(var j=0; j<lis.length; j++){
				$(lis[j]).removeClass("curr");
			}
			$(this).addClass("curr");
			var year = $(this).text();
			querySalary(year.substr(0,4));
		}); 
	}
}
function tabChange1(strYear){
	var syear=strYear+"年";
	var lis = $("#J-TabsNav > li");  
	for(var j=0; j<lis.length; j++){
		$(lis[j]).removeClass("curr");
	}
	for(var i=0; i<lis.length; i++){
		if($(lis[i]).text() == syear){
			$(lis[i]).addClass("curr");
			$("#loadingText").show();
			querySalary(syear.substr(0,4));
		}
	}
}
function iscroll(){
	var wh = $(window).height()-212-120; 
	if(myiscroll instanceof iScroll)
		myiscroll.destroy();
	$("#iscrollContent").css("height",wh+"px");
	myiscroll = new iScroll("iscrollContent",{bounce:false});
}